// AWTEventMulticaster.h: interface for the AWTEventMulticaster class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AWTEVENTMULTICASTER_H__DC9C0D2D_40B4_11D2_A3F1_006097A44215__INCLUDED_)
#define AFX_AWTEVENTMULTICASTER_H__DC9C0D2D_40B4_11D2_A3F1_006097A44215__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "AWTObject.h"
#include "AWTComponentListener.h"
#include "AWTActionListener.h"
#include "AWTFocusListener.h"
#include "AWTItemListener.h"
#include "AWTWindowListener.h"
#include "AWTAdjustmentListener.h"
#include "AWTTextListener.h"

class AFX_EXT_CLASS AWTEventMulticaster : public AWTObject,
                            public AWTComponentListener,
														public AWTActionListener,
														public AWTItemListener,
														public AWTMouseListener,
														public AWTMouseMotionListener,
														public AWTWindowListener,
														public AWTKeyListener,
														public AWTFocusListener,
														public AWTAdjustmentListener,
														public AWTTextListener
{
DECLARE_DYNAMIC(AWTEventMulticaster)
public:
	AWTEventMulticaster(AWTEventListener* a, AWTEventListener* b);
	virtual ~AWTEventMulticaster();

	AWTEventListener* remove(AWTEventListener* oldl);

  void componentResized(AWTComponentEvent* e) 
	{
    ((AWTComponentListener*)m_a)->componentResized(e);
    ((AWTComponentListener*)m_b)->componentResized(e);
  }

  void componentMoved(AWTComponentEvent* e) 
	{
    ((AWTComponentListener*)m_a)->componentMoved(e);
    ((AWTComponentListener*)m_b)->componentMoved(e);
  }

  void componentShown(AWTComponentEvent* e) 
	{
    ((AWTComponentListener*)m_a)->componentShown(e);
    ((AWTComponentListener*)m_b)->componentShown(e);
  }

  void componentHidden(AWTComponentEvent* e) 
	{
    ((AWTComponentListener*)m_a)->componentHidden(e);
    ((AWTComponentListener*)m_b)->componentHidden(e);
  }

	void actionPerformed(AWTActionEvent* e) 
	{
    ((AWTActionListener*)m_a)->actionPerformed(e);
    ((AWTActionListener*)m_b)->actionPerformed(e);
  }

	void itemStateChanged(AWTItemEvent* e) 
	{
    ((AWTItemListener*)m_a)->itemStateChanged(e);
    ((AWTItemListener*)m_b)->itemStateChanged(e);
  }

	void mouseClicked(AWTMouseEvent* e) 
	{
    ((AWTMouseListener*)m_a)->mouseClicked(e);
    ((AWTMouseListener*)m_b)->mouseClicked(e);
  }

	void mousePressed(AWTMouseEvent* e) 
	{
    ((AWTMouseListener*)m_a)->mousePressed(e);
    ((AWTMouseListener*)m_b)->mousePressed(e);
  }

	void mouseReleased(AWTMouseEvent* e) 
	{
    ((AWTMouseListener*)m_a)->mouseReleased(e);
    ((AWTMouseListener*)m_b)->mouseReleased(e);
  }

	void mouseEntered(AWTMouseEvent* e) 
	{
    ((AWTMouseListener*)m_a)->mouseEntered(e);
    ((AWTMouseListener*)m_b)->mouseEntered(e);
  }

	void mouseExited(AWTMouseEvent* e) 
	{
    ((AWTMouseListener*)m_a)->mouseExited(e);
    ((AWTMouseListener*)m_b)->mouseExited(e);
  }


	void mouseMoved(AWTMouseEvent* e) 
	{
    ((AWTMouseMotionListener*)m_a)->mouseMoved(e);
    ((AWTMouseMotionListener*)m_b)->mouseMoved(e);
  }

	void mouseDragged(AWTMouseEvent* e) 
	{
    ((AWTMouseMotionListener*)m_a)->mouseDragged(e);
    ((AWTMouseMotionListener*)m_b)->mouseDragged(e);
  }


  void windowOpened(AWTWindowEvent* e) 
	{
    ((AWTWindowListener*)m_a)->windowOpened(e);
    ((AWTWindowListener*)m_b)->windowOpened(e);
  }

	void windowClosing(AWTWindowEvent* e) 
	{
    ((AWTWindowListener*)m_a)->windowClosing(e);
    ((AWTWindowListener*)m_b)->windowClosing(e);
  }

	void windowClosed(AWTWindowEvent* e) 
	{
		((AWTWindowListener*)m_a)->windowClosed(e);
		((AWTWindowListener*)m_b)->windowClosed(e);
	}

	void windowIconified(AWTWindowEvent* e) 
	{
		((AWTWindowListener*)m_a)->windowIconified(e);
		((AWTWindowListener*)m_b)->windowIconified(e);
	}

	void windowDeiconified(AWTWindowEvent* e) 
	{
		((AWTWindowListener*)m_a)->windowDeiconified(e);
		((AWTWindowListener*)m_b)->windowDeiconified(e);
  }

	void windowActivated(AWTWindowEvent* e) 
	{
		((AWTWindowListener*)m_a)->windowActivated(e);
		((AWTWindowListener*)m_b)->windowActivated(e);
	}

	void windowDeactivated(AWTWindowEvent* e) 
	{
		((AWTWindowListener*)m_a)->windowDeactivated(e);
		((AWTWindowListener*)m_b)->windowDeactivated(e);
	}

	void keyTyped(AWTKeyEvent* e) 
	{
		((AWTKeyListener*)m_a)->keyTyped(e);
		((AWTKeyListener*)m_b)->keyTyped(e);
	}

	void keyPressed(AWTKeyEvent* e) 
	{
		((AWTKeyListener*)m_a)->keyPressed(e);
		((AWTKeyListener*)m_b)->keyPressed(e);
	}

	void keyReleased(AWTKeyEvent* e) 
	{
		((AWTKeyListener*)m_a)->keyReleased(e);
		((AWTKeyListener*)m_b)->keyReleased(e);
	}

	void focusGained(AWTFocusEvent* e) 
	{
		((AWTFocusListener*)m_a)->focusGained(e);
		((AWTFocusListener*)m_b)->focusGained(e);
	}

	void focusLost(AWTFocusEvent* e) 
	{
		((AWTFocusListener*)m_a)->focusLost(e);
		((AWTFocusListener*)m_b)->focusLost(e);
	}


  void adjustmentValueChanged(AWTAdjustmentEvent* e)
	{
		((AWTAdjustmentListener*)m_a)->adjustmentValueChanged(e);
		((AWTAdjustmentListener*)m_b)->adjustmentValueChanged(e);
	}

	void textValueChanged(AWTTextEvent* e) 
	{
		((AWTTextListener*)m_a)->textValueChanged(e);
		((AWTTextListener*)m_b)->textValueChanged(e);
	}


//////////////////////////////////////////////////////////////////////

	static AWTComponentListener* add(AWTComponentListener* a, AWTComponentListener* b);
  static AWTActionListener* add(AWTActionListener* a, AWTActionListener* b);
  static AWTFocusListener* add(AWTFocusListener* a, AWTFocusListener* b);
  static AWTKeyListener* add(AWTKeyListener* a, AWTKeyListener* b);
  static AWTItemListener* add(AWTItemListener* a, AWTItemListener* b);
  static AWTMouseListener* add(AWTMouseListener* a, AWTMouseListener* b);
  static AWTMouseMotionListener* add(AWTMouseMotionListener* a, AWTMouseMotionListener* b);
  static AWTWindowListener* add(AWTWindowListener* a, AWTWindowListener* b);
  static AWTAdjustmentListener* add(AWTAdjustmentListener* a, AWTAdjustmentListener* b);
  static AWTTextListener* add(AWTTextListener* a, AWTTextListener* b);

	static AWTComponentListener* remove(AWTComponentListener* l, AWTComponentListener* oldl) 
	{
		return (AWTComponentListener*) removeInternal(l, oldl);
  }

	static AWTActionListener* remove(AWTActionListener* l, AWTActionListener* oldl) 
	{
		return (AWTActionListener*) removeInternal(l, oldl);
  }

	static AWTFocusListener* remove(AWTFocusListener* l, AWTFocusListener* oldl) 
	{
		return (AWTFocusListener*) removeInternal(l, oldl);
  }

	static AWTKeyListener* remove(AWTKeyListener* l, AWTKeyListener* oldl) 
	{
		return (AWTKeyListener*) removeInternal(l, oldl);
  }

	static AWTItemListener* remove(AWTItemListener* l, AWTItemListener* oldl) 
	{
		return (AWTItemListener*) removeInternal(l, oldl);
  }

	static AWTMouseListener* remove(AWTMouseListener* l, AWTMouseListener* oldl) 
	{
		return (AWTMouseListener*) removeInternal(l, oldl);
  }

	static AWTMouseMotionListener* remove(AWTMouseMotionListener* l, AWTMouseMotionListener* oldl) 
	{
		return (AWTMouseMotionListener*) removeInternal(l, oldl);
  }

	static AWTWindowListener* remove(AWTWindowListener* l, AWTWindowListener* oldl) 
	{
		return (AWTWindowListener*) removeInternal(l, oldl);
  }

	static AWTAdjustmentListener* remove(AWTAdjustmentListener* l, AWTAdjustmentListener* oldl) 
	{
		return (AWTAdjustmentListener*) removeInternal(l, oldl);
  }

	static AWTTextListener* remove(AWTTextListener* l, AWTTextListener* oldl) 
	{
		return (AWTTextListener*) removeInternal(l, oldl);
  }


	AWTEventListener* getEventListener()
		{return reinterpret_cast<AWTEventListener*>(this);}

	BOOL isMultiCaster()
		{return TRUE;}

protected:		
/*
	static AWTEventListener* addInternal(AWTEventListener* a, AWTEventListener* b) 
	{
		if (a == NULL)  return b;
		if (b == NULL)  return a;
		AWTEventMulticaster* m = new AWTEventMulticaster(a, b);

//		return dynamic_cast<AWTEventListener*>(m);
		return m->getEventListener();
  }
*/
  static AWTEventListener* removeInternal(AWTEventListener* l, AWTEventListener* oldl) 
	{
		if (l == oldl || l == NULL) 
		{
	    return NULL;
		} 
		else if (l->isMultiCaster()) 
//		else if (l->IsKindOf(RUNTIME_CLASS(AWTMultiCaster))) 
		{
	    return (reinterpret_cast<AWTEventMulticaster*>(l))->remove(oldl);
		} 
		else 
		{
	    return l;		// it's not here
		}
  }

	AWTEventListener* m_a;
	AWTEventListener* m_b;
};

#endif // !defined(AFX_AWTEVENTMULTICASTER_H__DC9C0D2D_40B4_11D2_A3F1_006097A44215__INCLUDED_)
